<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <el-form :model="formData" :rules="rules" label-width="120px" style="margin-left: 120px; margin-top:30px">
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="formData.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="password">
                <el-input v-model="formData.password" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="btnOK">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <userInfo />

          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <jobInfo />

          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getUserDetails, saveUserDetailsAPI } from '@/api/user'
import jobInfo from './job-info.vue'
import userInfo from './user-info'
export default {
  components: {
    jobInfo, userInfo
  },
  data() {
    return {
      formData: {
        username: '',
        password: ''
      },
      rules: {
        username: [{ required: true, message: '该项不能为空', trigger: 'blur' }],
        password: [{ required: true, message: '该项不能为空', trigger: 'blur' }]
      },
      userId: this.$route.params.id
    }
  },
  async created() {
    const res = await getUserDetails(this.userId)
    this.formData = { ...res, password: '' }
  },
  methods: {
    async btnOK() {
      await saveUserDetailsAPI({ id: this.userId, ...this.formData })
      await this.$message.success('更新成功')
    }
  }
}
</script>

<style>

</style>
